package com.xonro.common.histrans.sfeg.biz.base;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.ctx.HistoryTransContext;
import com.xonro.common.histrans.base.consts.SfegConst;
import com.xonro.common.histrans.sfeg.biz.common.SfegRecordTransBiz;
import com.xonro.common.histrans.sfeg.ctx.SfecProcessCreateContext;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BaseUserInfoBiz extends SfegRecordTransBiz {
    @Override
    protected void transProcess0(SfecProcessCreateContext createContext) {
        List<RowMap> maps = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMaps("SELECT * FROM Tb_UserInfo WHERE dept like '1040%'");
        for (RowMap m : maps) {
            int user = SDK.getORGAPI().createUser(m.getString("dept"), m.getString("loginName"), m.getString("usName"), null, "123456", false);
        }
        for (RowMap m : maps) {
            Map<String, Object> map = new HashMap<>();
            map.put("USERNO", m.getString("gh"));
            SDK.getORGAPI().updateUser(m.getString("loginName"), map);
        }
    }

    @Override
    protected String getProcessDefId() {
        return null;
    }

    @Override
    protected RowMap getMainData() {
        return null;
    }

    @Override
    protected String getActivityDefId() {
        return null;
    }

    @Override
    protected String getTitle(HistoryTransContext ctx) {
        String usCode = ctx.getMainData().getString("usCode");
        String usName = ctx.getMainData().getString("usName");
        return usName + usCode;
    }

    @Override
    protected String getEnCode(HistoryTransContext ctx) {
        return ctx.getMainData().getString("usCode");
    }

    @Override
    protected String getOuterTable(SfecProcessCreateContext historyTransContext) {
        return "Tb_UserInfo";
    }

    @Override
    protected String getPk(SfecProcessCreateContext historyTransContext) {
        return historyTransContext.getMainData().getString("usCode");
    }

    @Override
    protected List<RowMap> getMainDatas() {
        return SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMaps("SELECT * FROM Tb_UserInfo WHERE dept like '1040%'");
    }
}
